diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AbstractTypedAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AbstractTypedAnalyzer.java index f0cff57e98c4..bab87b99177d 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AbstractTypedAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AbstractTypedAnalyzer.java @@ -38,14 +38,18 @@ import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.modules.web.beans.analysis.CdiAnalysisResult; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.TYPED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.TYPED_JAKARTA; /** * @author ads * */ public abstract class AbstractTypedAnalyzer { - - public void analyze( Element element, TypeMirror elementType, + + public void analyze( Element element, TypeMirror elementType, AtomicBoolean cancel , CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); @@ -67,27 +71,26 @@ public void analyze( Element element, TypeMirror elementType, if ( cancel.get()){ return; } - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES_JAKARTA, compInfo)) + if (AnnotationUtil.hasAnnotation(element, compInfo, SPECIALIZES_JAKARTA, SPECIALIZES)) { result.requireCdiEnabled(element); checkSpecializes( element , elementType , list, cancel , result ); } } - + protected abstract void checkSpecializes( Element element, TypeMirror elementType, List restrictedTypes, AtomicBoolean cancel , CdiAnalysisResult result ); - protected boolean hasBeanType( Element subject, TypeMirror elementType, + protected boolean hasBeanType( Element subject, TypeMirror elementType, TypeMirror requiredBeanType,CompilationInfo compInfo ) { return compInfo.getTypes().isSubtype(elementType, requiredBeanType); } - - protected abstract void addError ( Element element , + + protected abstract void addError ( Element element , CdiAnalysisResult result ); - protected void collectAncestors(TypeElement type , Set ancestors, + protected void collectAncestors(TypeElement type , Set ancestors, CompilationInfo compInfo ) { TypeMirror superclass = type.getSuperclass(); @@ -97,7 +100,7 @@ protected void collectAncestors(TypeElement type , Set ancestors, addAncestor(interfaze, ancestors, compInfo); } } - + private void addAncestor( TypeMirror parent , Set ancestors, CompilationInfo compInfo) { @@ -114,26 +117,24 @@ private void addAncestor( TypeMirror parent , Set ancestors, collectAncestors((TypeElement)parentElement, ancestors, compInfo); } } - - protected List getRestrictedTypes(Element element, + + protected List getRestrictedTypes(Element element, CompilationInfo compInfo , AtomicBoolean cancel) { - AnnotationMirror typedMirror = AnnotationUtil.getAnnotationMirror(element, AnnotationUtil.TYPED_JAKARTA, compInfo); - if (typedMirror == null) { - typedMirror = AnnotationUtil.getAnnotationMirror(element, AnnotationUtil.TYPED, compInfo); - } + AnnotationMirror typedMirror = AnnotationUtil.getAnnotationMirror( + element, compInfo, TYPED_JAKARTA, TYPED); if ( typedMirror == null ){ return null; } - Map values = + Map values = typedMirror.getElementValues(); AnnotationValue restrictedTypes = null; - for (Entry entry : - values.entrySet() ) + for (Entry entry : + values.entrySet() ) { ExecutableElement key = entry.getKey(); AnnotationValue value = entry.getValue(); - if ( AnnotationUtil.VALUE.contentEquals(key.getSimpleName())){ + if ( AnnotationUtil.VALUE.contentEquals(key.getSimpleName())){ restrictedTypes = value; break; } @@ -146,7 +147,7 @@ protected List getRestrictedTypes(Element element, } Object value = restrictedTypes.getValue(); if ( value instanceof List ){ - List result = new ArrayList(((List)value).size()); + List result = new ArrayList<>(((List)value).size()); for( Object type : (List)value){ AnnotationValue annotationValue = (AnnotationValue)type; type = annotationValue.getValue(); @@ -158,20 +159,20 @@ protected List getRestrictedTypes(Element element, } return Collections.emptyList(); } - + protected Set getUnrestrictedBeanTypes( TypeElement element, CompilationInfo compInfo) { - Set set = new HashSet(); + Set set = new HashSet<>(); set.add( element ); collectAncestors(element, set, compInfo); return set; } - + protected Set getElements( Collection types , CompilationInfo info ) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (TypeMirror typeMirror : types) { Element element = info.getTypes().asElement(typeMirror); if ( element instanceof TypeElement ){ @@ -180,5 +181,5 @@ protected Set getElements( Collection types , } return result; } - + } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AnnotationUtil.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AnnotationUtil.java index ff7fe3e9bb67..25f57c86dbea 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AnnotationUtil.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/AnnotationUtil.java @@ -173,29 +173,42 @@ public final class AnnotationUtil { private AnnotationUtil(){ } - public static boolean hasAnnotation(Element element, String annotation, - CompilationInfo info ) + /** + * @param element + * @param info + * @param annotationFqns + * @return true if at least one annotation from {@code annotationFqns} is + * present + */ + public static boolean hasAnnotation(Element element, + CompilationInfo info, String... annotationFqns ) { - return getAnnotationMirror(element, annotation, info)!=null; + return getAnnotationMirror(element, info, annotationFqns) != null; } - public static AnnotationMirror getAnnotationMirror(Element element, - String annotation,CompilationInfo info ) + /** + * @param element + * @param model + * @param annotationFqns + * @return true if at least one annotation from {@code annotationFqns} is + * present + */ + public static boolean hasAnnotation(Element element, + WebBeansModel model, String... annotationFqns) { - return getAnnotationMirror(element, info, annotation); + return hasAnnotation(element, model.getCompilationController(), annotationFqns); } /** - * return AnnotationMirror for first found annotation from annotationFqns * @param element * @param info * @param annotationFqns - * @return + * @return AnnotationMirror for first found annotation from annotationFqns */ public static AnnotationMirror getAnnotationMirror(Element element, CompilationInfo info , String... annotationFqns) { - Set set = new HashSet(); + Set set = new HashSet<>(); Elements els = info.getElements(); for( String annotation : annotationFqns){ TypeElement annotationElement = els.getTypeElement( @@ -220,26 +233,25 @@ public static AnnotationMirror getAnnotationMirror(Element element, public static boolean isSessionBean(Element element , CompilationInfo compInfo ) { - return getAnnotationMirror(element, compInfo, STATEFUL, STATELESS, SINGLETON, STATEFUL_JAKARTA, STATELESS_JAKARTA, SINGLETON_JAKARTA) != null; + return hasAnnotation(element, compInfo, STATEFUL, STATELESS, SINGLETON, STATEFUL_JAKARTA, STATELESS_JAKARTA, SINGLETON_JAKARTA); } public static boolean isDelegate(Element element, TypeElement parent, WebBeansModel model ) { - return (AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN, model.getCompilationController()) - && AnnotationUtil.hasAnnotation(parent, AnnotationUtil.DECORATOR, model.getCompilationController())) - || (AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN_JAKARTA, model.getCompilationController()) - && AnnotationUtil.hasAnnotation(parent, AnnotationUtil.DECORATOR_JAKARTA, model.getCompilationController())); + return (AnnotationUtil.hasAnnotation(element, model, DELEGATE_FQN) + && AnnotationUtil.hasAnnotation(parent, model, DECORATOR)) + || (AnnotationUtil.hasAnnotation(element, model, DELEGATE_FQN_JAKARTA) + && AnnotationUtil.hasAnnotation(parent, model, DECORATOR_JAKARTA)); } public static boolean isLifecycleCallback( ExecutableElement element , CompilationInfo info ) { - AnnotationMirror annotationMirror = getAnnotationMirror(element, info, + return hasAnnotation(element, info, POST_ACTIVATE, POST_CONSTRUCT, PRE_DESTROY, PRE_PASSIVATE, POST_ACTIVATE_JAKARTA, POST_CONSTRUCT_JAKARTA, PRE_DESTROY_JAKARTA, PRE_PASSIVATE_JAKARTA ); - return annotationMirror != null; } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/CtorAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/CtorAnalyzer.java index 09657d0853da..183b64a2c7c2 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/CtorAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/CtorAnalyzer.java @@ -29,6 +29,10 @@ import org.netbeans.modules.web.beans.analysis.CdiAnalysisResult; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN_JAKARTA; /** * @author ads @@ -49,16 +53,14 @@ public void analyze( Element element, TypeElement parent, if ( cancel.get() ){ return; } - boolean isDisposer = AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN_JAKARTA, result.getInfo()); - boolean isObserver = AnnotationUtil.hasAnnotation(param, AnnotationUtil.OBSERVES_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(param, AnnotationUtil.OBSERVES_FQN_JAKARTA, result.getInfo()); + boolean isDisposer = AnnotationUtil.hasAnnotation(param, result.getInfo(), DISPOSES_FQN_JAKARTA, DISPOSES_FQN); + boolean isObserver = AnnotationUtil.hasAnnotation(param, result.getInfo(), OBSERVES_FQN_JAKARTA, OBSERVES_FQN); if ( isDisposer || isObserver ){ result.requireCdiEnabled(element); - String annotation = isDisposer ? AnnotationUtil.DISPOSES : + String annotation = isDisposer ? AnnotationUtil.DISPOSES : AnnotationUtil.OBSERVES; result.addError( element, NbBundle.getMessage( - CtorAnalyzer.class, "ERR_BadAnnotationParamCtor", annotation)); // NOI18N + CtorAnalyzer.class, "ERR_BadAnnotationParamCtor", annotation)); // NOI18N break; } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingAnalyzer.java index c1b42e171d8d..e382ef8ba071 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingAnalyzer.java @@ -34,13 +34,16 @@ import org.netbeans.modules.web.beans.api.model.WebBeansModel; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_BINDING_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_BINDING_FQN_JAKARTA; + /** * @author ads * */ public class InterceptorBindingAnalyzer implements AnnotationAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AnnotationModelAnalyzer.AnnotationAnalyzer#analyze(javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @@ -49,8 +52,7 @@ public void analyze( TypeElement element, WebBeansModel model, AtomicBoolean cancel , Result result ) { - if (!(AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_BINDING_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_BINDING_FQN_JAKARTA, model.getCompilationController()))) + if (!AnnotationUtil.hasAnnotation(element, model, INTERCEPTOR_BINDING_FQN_JAKARTA, INTERCEPTOR_BINDING_FQN)) { return; } @@ -61,7 +63,7 @@ public void analyze( TypeElement element, WebBeansModel model, return; } if (!analyzer.hasRuntimeRetention()) { - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage(InterceptorBindingAnalyzer.class, INCORRECT_RUNTIME)); } @@ -69,7 +71,7 @@ public void analyze( TypeElement element, WebBeansModel model, return; } if (!analyzer.hasTarget()) { - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage(InterceptorBindingAnalyzer.class, "ERR_IncorrectInterceptorBindingTarget")); // NOI18N } @@ -81,11 +83,11 @@ public void analyze( TypeElement element, WebBeansModel model, if ( cancel.get() ){ return; } - checkTransitiveInterceptorBindings( element, declaredTargetTypes, + checkTransitiveInterceptorBindings( element, declaredTargetTypes, model , result ); } } - + private void checkTransitiveInterceptorBindings( TypeElement element, Set declaredTargetTypes, WebBeansModel model, Result result ) @@ -108,7 +110,7 @@ private void checkTransitiveInterceptorBindings( TypeElement element, if (bindingTargetTypes.size() == 1 && bindingTargetTypes.contains(ElementType.TYPE)) { - result.addError(element, model , + result.addError(element, model , NbBundle.getMessage(InterceptorBindingAnalyzer.class, "ERR_IncorrectTransitiveInterceptorBinding", // NOI18N ((TypeElement) binding).getQualifiedName().toString())); @@ -118,7 +120,7 @@ private void checkTransitiveInterceptorBindings( TypeElement element, } private static class InterceptorTargetAnalyzer extends CdiAnnotationAnalyzer { - + InterceptorTargetAnalyzer( TypeElement element , WebBeansModel model , Result result) { @@ -140,7 +142,7 @@ protected String getCdiMetaAnnotation() { protected TargetVerifier getTargetVerifier() { return InterceptorBindingVerifier.getInstance(); } - + } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingMembersAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingMembersAnalyzer.java index 2720cef2c3f6..349f3350f971 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingMembersAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/InterceptorBindingMembersAnalyzer.java @@ -35,6 +35,11 @@ import org.openide.util.NbBundle; import org.netbeans.spi.editor.hints.Severity; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_BINDING_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_BINDING_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NON_BINDING; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NON_BINDING_JAKARTA; + /** @@ -50,17 +55,16 @@ public class InterceptorBindingMembersAnalyzer implements AnnotationAnalyzer { public void analyze( TypeElement element, AtomicBoolean cancel, CdiAnalysisResult result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_BINDING_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_BINDING_FQN_JAKARTA, result.getInfo())) + if (AnnotationUtil.hasAnnotation(element, result.getInfo(), INTERCEPTOR_BINDING_FQN_JAKARTA, INTERCEPTOR_BINDING_FQN)) { checkMembers(element, result, NbBundle.getMessage( - QualifierAnalyzer.class, + QualifierAnalyzer.class, "WARN_ArrayAnnotationValuedIBindingMember")); // NOI18N } } - - protected void checkMembers( TypeElement element, CdiAnalysisResult result , - String localizedWarning ) + + protected void checkMembers( TypeElement element, CdiAnalysisResult result , + String localizedWarning ) { List methods = ElementFilter.methodsIn( element.getEnclosedElements()); @@ -71,19 +75,18 @@ protected void checkMembers( TypeElement element, CdiAnalysisResult result , warning = true; } else if ( returnType.getKind() == TypeKind.DECLARED){ - Element returnElement = result.getInfo().getTypes().asElement( + Element returnElement = result.getInfo().getTypes().asElement( returnType ); warning = returnElement.getKind() == ElementKind.ANNOTATION_TYPE; } if ( !warning ){ continue; } - if (AnnotationUtil.hasAnnotation(executableElement, AnnotationUtil.NON_BINDING, result.getInfo()) - || AnnotationUtil.hasAnnotation(executableElement, AnnotationUtil.NON_BINDING_JAKARTA, result.getInfo())) + if (AnnotationUtil.hasAnnotation(executableElement, result.getInfo(), NON_BINDING_JAKARTA, NON_BINDING)) { continue; } - result.addNotification(Severity.WARNING, element, localizedWarning); + result.addNotification(Severity.WARNING, element, localizedWarning); } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/QualifierAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/QualifierAnalyzer.java index 100b31d75196..4bdd32541c53 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/QualifierAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/QualifierAnalyzer.java @@ -18,23 +18,16 @@ */ package org.netbeans.modules.web.beans.analysis.analyzer.annotation; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.ElementFilter; import org.netbeans.modules.web.beans.analysis.CdiAnalysisResult; -import org.netbeans.modules.web.beans.analysis.analyzer.AnnotationElementAnalyzer.AnnotationAnalyzer; import org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil; import org.openide.util.NbBundle; -import org.netbeans.spi.editor.hints.Severity; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.QUALIFIER_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.QUALIFIER_FQN_JAKARTA; /** * @author ads @@ -49,31 +42,30 @@ public class QualifierAnalyzer extends InterceptorBindingMembersAnalyzer { public void analyze( TypeElement element, AtomicBoolean cancel, CdiAnalysisResult result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.QUALIFIER_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.QUALIFIER_FQN_JAKARTA, result.getInfo())) + if (AnnotationUtil.hasAnnotation(element, result.getInfo(), QUALIFIER_FQN_JAKARTA, QUALIFIER_FQN)) { result.requireCdiEnabled(element); - QualifierTargetAnalyzer analyzer = new QualifierTargetAnalyzer(element, + QualifierTargetAnalyzer analyzer = new QualifierTargetAnalyzer(element, result ); if ( !analyzer.hasRuntimeRetention() ){ - result.addError( element, - NbBundle.getMessage(QualifierTargetAnalyzer.class, + result.addError( element, + NbBundle.getMessage(QualifierTargetAnalyzer.class, INCORRECT_RUNTIME)); } if ( !analyzer.hasTarget()){ - result.addError( element, - NbBundle.getMessage(QualifierTargetAnalyzer.class, + result.addError( element, + NbBundle.getMessage(QualifierTargetAnalyzer.class, "ERR_IncorrectQualifierTarget")); // NOI18N } if ( cancel.get() ){ return; } checkMembers( element, result , NbBundle.getMessage( - QualifierAnalyzer.class, + QualifierAnalyzer.class, "WARN_ArrayAnnotationValuedQualifierMember")); // NOI18N } } - + private static class QualifierTargetAnalyzer extends CdiAnnotationAnalyzer{ QualifierTargetAnalyzer( TypeElement element, CdiAnalysisResult result) @@ -96,6 +88,6 @@ protected String getCdiMetaAnnotation() { protected TargetVerifier getTargetVerifier() { return QualifierVerifier.getInstance( true ); } - + } } \ No newline at end of file diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/ScopeAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/ScopeAnalyzer.java index 7114455bc7eb..47f13a81e31c 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/ScopeAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/ScopeAnalyzer.java @@ -28,6 +28,11 @@ import org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NORMAL_SCOPE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NORMAL_SCOPE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SCOPE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SCOPE_FQN_JAKARTA; + /** * @author ads @@ -43,36 +48,34 @@ public void analyze( TypeElement element, AtomicBoolean cancel, CdiAnalysisResult result) { CompilationInfo compInfo = result.getInfo(); - boolean isScope = AnnotationUtil.hasAnnotation(element, AnnotationUtil.SCOPE_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SCOPE_FQN_JAKARTA, compInfo); - boolean isNormalScope = AnnotationUtil.hasAnnotation(element, AnnotationUtil.NORMAL_SCOPE_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.NORMAL_SCOPE_FQN_JAKARTA, compInfo); + boolean isScope = AnnotationUtil.hasAnnotation(element, compInfo, SCOPE_FQN_JAKARTA, SCOPE_FQN); + boolean isNormalScope = AnnotationUtil.hasAnnotation(element, compInfo, NORMAL_SCOPE_FQN_JAKARTA, NORMAL_SCOPE_FQN); if ( isScope || isNormalScope ){ result.requireCdiEnabled(element); - ScopeTargetAnalyzer analyzer = new ScopeTargetAnalyzer(element, + ScopeTargetAnalyzer analyzer = new ScopeTargetAnalyzer(element, result, isNormalScope); if ( cancel.get() ){ return; } if ( !analyzer.hasRuntimeRetention() ){ - result.addError( element, - NbBundle.getMessage(ScopeAnalyzer.class, + result.addError( element, + NbBundle.getMessage(ScopeAnalyzer.class, INCORRECT_RUNTIME)); } if ( cancel.get() ){ return; } if ( !analyzer.hasTarget()){ - result.addError( element, - NbBundle.getMessage(ScopeAnalyzer.class, + result.addError( element, + NbBundle.getMessage(ScopeAnalyzer.class, "ERR_IncorrectScopeTarget")); // NOI18N } } } - + private static class ScopeTargetAnalyzer extends CdiAnnotationAnalyzer { - - ScopeTargetAnalyzer(TypeElement element, CdiAnalysisResult result, + + ScopeTargetAnalyzer(TypeElement element, CdiAnalysisResult result, boolean normalScope ) { super( element , result ); @@ -100,7 +103,7 @@ protected String getCdiMetaAnnotation() { } } - private boolean isNormalScope; + private final boolean isNormalScope; } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/StereotypeAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/StereotypeAnalyzer.java index e88b6c8101ad..60431f1d7dd1 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/StereotypeAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/annotation/StereotypeAnalyzer.java @@ -41,24 +41,28 @@ import org.openide.util.NbBundle; import org.netbeans.spi.editor.hints.Severity; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STEREOTYPE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STEREOTYPE_FQN_JAKARTA; + /** * @author ads * */ public class StereotypeAnalyzer extends AbstractScopedAnalyzer implements AnnotationAnalyzer { - - + + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AnnotationModelAnalyzer.AnnotationAnalyzer#analyze(javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @Override public void analyze( TypeElement element, WebBeansModel model , - AtomicBoolean cancel , + AtomicBoolean cancel , Result result) { - boolean isStereotype = AnnotationUtil.hasAnnotation(element, AnnotationUtil.STEREOTYPE_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.STEREOTYPE_FQN_JAKARTA, model.getCompilationController()); + boolean isStereotype = AnnotationUtil.hasAnnotation(element, model, STEREOTYPE_FQN_JAKARTA, STEREOTYPE_FQN); if ( !isStereotype ){ return; } @@ -99,7 +103,7 @@ private void checkQualifers( TypeElement element, WebBeansModel model, List qualifiers = model.getQualifiers(element, true); for (AnnotationMirror annotationMirror : qualifiers) { Element annotation = annotationMirror.getAnnotationType().asElement(); - if ( annotation instanceof TypeElement && + if ( annotation instanceof TypeElement && ( ((TypeElement)annotation).getQualifiedName().contentEquals(AnnotationUtil.NAMED) || ((TypeElement)annotation).getQualifiedName().contentEquals(AnnotationUtil.NAMED_JAKARTA) @@ -109,12 +113,12 @@ private void checkQualifers( TypeElement element, WebBeansModel model, continue; } else { - result.addNotification( Severity.WARNING , element, model, - NbBundle.getMessage(StereotypeAnalyzer.class, + result.addNotification( Severity.WARNING , element, model, + NbBundle.getMessage(StereotypeAnalyzer.class, "WARN_QualifiedStereotype")); // NOI18N break; } - } + } } private void checkTyped( TypeElement element, WebBeansModel model, @@ -125,8 +129,8 @@ private void checkTyped( TypeElement element, WebBeansModel model, typed = AnnotationUtil.getAnnotationMirror(element, model.getCompilationController(), AnnotationUtil.TYPED); } if ( typed != null ){ - result.addNotification( Severity.WARNING , element, model, - NbBundle.getMessage(StereotypeAnalyzer.class, + result.addNotification( Severity.WARNING , element, model, + NbBundle.getMessage(StereotypeAnalyzer.class, "WARN_TypedStereotype")); // NOI18N } } @@ -157,7 +161,7 @@ private void checkTransitiveStereotypes( TypeElement element, } else { String fqn = stereotype.getQualifiedName().toString(); - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage( StereotypeAnalyzer.class, "ERR_IncorrectTransitiveTarget", // NOI18N @@ -180,7 +184,7 @@ private void checkInterceptorBindings( TypeElement element, } int interceptorsCount = model.getInterceptorBindings(element).size(); if (interceptorsCount != 0) { - result.addError(element,model, + result.addError(element,model, NbBundle.getMessage(StereotypeAnalyzer.class, "ERR_IncorrectTargetWithInterceptorBindings")); // NOI18N } @@ -189,16 +193,16 @@ private void checkInterceptorBindings( TypeElement element, private Set checkDefinition( TypeElement element, WebBeansModel model , Result result ) { - StereotypeTargetAnalyzer analyzer = new StereotypeTargetAnalyzer(element, + StereotypeTargetAnalyzer analyzer = new StereotypeTargetAnalyzer(element, model, result ); if ( !analyzer.hasRuntimeRetention()){ - result.addError( element, model, - NbBundle.getMessage(StereotypeAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(StereotypeAnalyzer.class, INCORRECT_RUNTIME)); } if ( !analyzer.hasTarget()){ - result.addError( element, model, - NbBundle.getMessage(StereotypeAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(StereotypeAnalyzer.class, "ERR_IncorrectStereotypeTarget")); // NOI18N return null; } @@ -210,22 +214,20 @@ private Set checkDefinition( TypeElement element, private void checkName( TypeElement element, WebBeansModel model, Result result ) { - AnnotationMirror named = AnnotationUtil.getAnnotationMirror(element, AnnotationUtil.NAMED_JAKARTA, model.getCompilationController()); - if (named == null) { - named = AnnotationUtil.getAnnotationMirror(element, AnnotationUtil.NAMED, model.getCompilationController()); - } + AnnotationMirror named = AnnotationUtil.getAnnotationMirror( + element, model.getCompilationController(), NAMED_JAKARTA, NAMED); if ( named == null ){ return; } - Map members = + Map members = named.getElementValues(); - for (Entry entry: - members.entrySet()) + for (Entry entry: + members.entrySet()) { ExecutableElement member = entry.getKey(); - if ( member.getSimpleName().contentEquals(AnnotationUtil.VALUE)){ - result.addError( element, model, - NbBundle.getMessage(StereotypeAnalyzer.class, + if ( member.getSimpleName().contentEquals(AnnotationUtil.VALUE)){ + result.addError( element, model, + NbBundle.getMessage(StereotypeAnalyzer.class, "ERR_NonEmptyNamedStereotype")); // NOI18N } } @@ -263,7 +265,7 @@ protected String getCdiMetaAnnotation() { protected TargetVerifier getTargetVerifier() { return StereotypeVerifier.getInstance(); } - + } - + } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/DelegateFieldAnalizer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/DelegateFieldAnalizer.java index 9b64ae82aa12..2b100a5eb3d5 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/DelegateFieldAnalizer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/DelegateFieldAnalizer.java @@ -37,6 +37,13 @@ import org.netbeans.modules.web.beans.hints.EditorAnnotationsHelper; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; + /** * @author ads @@ -53,25 +60,19 @@ public void analyze( VariableElement element, TypeMirror elementType, CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - if (! (AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN_JAKARTA, compInfo) - )) + if (!AnnotationUtil.hasAnnotation(element, compInfo, DELEGATE_FQN_JAKARTA, DELEGATE_FQN)) { return; } result.requireCdiEnabled(element); - if (! (AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN_JAKARTA, compInfo) - )) + if (!AnnotationUtil.hasAnnotation(element, compInfo, INJECT_FQN_JAKARTA, INJECT_FQN)) { result.addError(element, NbBundle.getMessage( DelegateFieldAnalizer.class, "ERR_DelegateHasNoInject")); // NOI18N } Element clazz = element.getEnclosingElement(); - if (! (AnnotationUtil.hasAnnotation(clazz, AnnotationUtil.DECORATOR, compInfo) - || AnnotationUtil.hasAnnotation(clazz, AnnotationUtil.DECORATOR_JAKARTA, compInfo) - )) + if (! AnnotationUtil.hasAnnotation(clazz, compInfo, DECORATOR_JAKARTA, DECORATOR)) { result.addError(element, NbBundle.getMessage( DelegateFieldAnalizer.class, @@ -92,7 +93,7 @@ private void checkDelegateType( VariableElement element, TypeMirror elementType, TypeElement parent, CdiAnalysisResult result ) { - Collection decoratedTypes = getDecoratedTypes( parent , + Collection decoratedTypes = getDecoratedTypes( parent , result.getInfo() ); for (TypeMirror decoratedType : decoratedTypes) { if ( !result.getInfo().getTypes().isSubtype( elementType,decoratedType )){ @@ -104,18 +105,18 @@ private void checkDelegateType( VariableElement element, } } - public static Collection getDecoratedTypes( TypeElement element , - CompilationInfo info ) + public static Collection getDecoratedTypes( TypeElement element , + CompilationInfo info ) { TypeElement serializable = info.getElements().getTypeElement( Serializable.class.getCanonicalName()); - Collection result = new LinkedList(); + Collection result = new LinkedList<>(); collectDecoratedTypes( element.asType() , result , serializable, info ); return result; } private static void collectDecoratedTypes( TypeMirror type, - Collection result, TypeElement serializable, + Collection result, TypeElement serializable, CompilationInfo info) { List directSupertypes = info.getTypes(). diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/InjectionPointAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/InjectionPointAnalyzer.java index 971021733f3a..47bded315b7c 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/InjectionPointAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/InjectionPointAnalyzer.java @@ -18,7 +18,6 @@ */ package org.netbeans.modules.web.beans.analysis.analyzer.field; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -28,7 +27,6 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; -import javax.swing.text.Document; import org.netbeans.api.java.source.ElementHandle; import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationHelper; @@ -45,27 +43,32 @@ import org.netbeans.spi.editor.hints.Severity; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED_JAKARTA; + /** * @author ads * */ public class InjectionPointAnalyzer extends AbstractDecoratorAnalyzer implements FieldAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.FieldModelAnalyzer.FieldAnalyzer#analyze(javax.lang.model.element.VariableElement, javax.lang.model.type.TypeMirror, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @Override public void analyze( final VariableElement element, TypeMirror elementType, TypeElement parent, WebBeansModel model, - AtomicBoolean cancel , + AtomicBoolean cancel , Result result ) { try { if (model.isInjectionPoint(element) ){ boolean isDelegate = false; result.requireCdiEnabled(element, model); - checkInjectionPointMetadata( element, elementType , parent, model , + checkInjectionPointMetadata( element, elementType , parent, model , cancel , result ); checkNamed( element, model , cancel, result); if ( cancel.get() ){ @@ -90,14 +93,12 @@ public void analyze( final VariableElement element, TypeMirror elementType, EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance( result); if ( helper != null ){ - helper.addEventInjectionPoint( result, + helper.addEventInjectionPoint( result, modelHandle.resolve(result.getInfo())); } } - else if ( isDelegate - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN_JAKARTA, model.getCompilationController()) - ) + else if (isDelegate + || AnnotationUtil.hasAnnotation(element, model, DELEGATE_FQN_JAKARTA, DELEGATE_FQN)) { return; } @@ -106,7 +107,7 @@ else if ( isDelegate EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance( result); if (helper != null ){ - helper.addInjectionPoint( result, + helper.addInjectionPoint( result, modelHandle.resolve(result.getInfo())); } } @@ -117,20 +118,16 @@ else if ( isDelegate informInjectionPointDefError(e, element, model, result ); } } - + private void checkNamed( VariableElement element, WebBeansModel model, AtomicBoolean cancel, Result result ) { if( cancel.get() ){ return; } - if ( - AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED_JAKARTA, model.getCompilationController()) - ) - { - result.addNotification( Severity.WARNING , element, model, - NbBundle.getMessage(InjectionPointAnalyzer.class, + if (AnnotationUtil.hasAnnotation(element, model, NAMED_JAKARTA, NAMED)) { + result.addNotification( Severity.WARNING , element, model, + NbBundle.getMessage(InjectionPointAnalyzer.class, "WARN_NamedInjectionPoint")); // NOI18N } } @@ -139,15 +136,15 @@ private void checkNamed( VariableElement element, WebBeansModel model, * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractDecoratorAnalyzer#addClassError(javax.lang.model.element.VariableElement, java.lang.Object, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, org.netbeans.modules.web.beans.analysis.analyzer.ModelAnalyzer.Result) */ @Override - protected void addClassError( VariableElement element, Void fake, + protected void addClassError( VariableElement element, Void fake, TypeElement decoratedBean, WebBeansModel model, Result result ) { - result.addError( element , model, - NbBundle.getMessage(InjectionPointAnalyzer.class, + result.addError( element , model, + NbBundle.getMessage(InjectionPointAnalyzer.class, "ERR_FinalDecoratedBean", // NOI18N decoratedBean.getQualifiedName().toString())); } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractDecoratorAnalyzer#addMethodError(javax.lang.model.element.VariableElement, java.lang.Object, javax.lang.model.element.TypeElement, javax.lang.model.element.Element, org.netbeans.modules.web.beans.api.model.WebBeansModel, org.netbeans.modules.web.beans.analysis.analyzer.ModelAnalyzer.Result) */ @@ -175,7 +172,7 @@ private void checkInjectionPointMetadata( VariableElement element, if (injectionPointType == null) { return; } - Element varElement = model.getCompilationController().getTypes().asElement( + Element varElement = model.getCompilationController().getTypes().asElement( elementType ); if ( !injectionPointType.equals(varElement)){ return; @@ -197,7 +194,7 @@ private void checkInjectionPointMetadata( VariableElement element, try { String scope = model.getScope( parent ); if ( scope != null && !AnnotationUtil.DEPENDENT.equals( scope ) && !AnnotationUtil.DEPENDENT_JAKARTA.equals( scope )){ - result.addError(element , model, + result.addError(element , model, NbBundle.getMessage( InjectionPointAnalyzer.class, "ERR_WrongQualifierInjectionPointMeta")); // NOI18N } @@ -223,8 +220,8 @@ private void checkResult( DependencyInjectionResult res , } } - private void informInjectionPointDefError(InjectionPointDefinitionError exception , - Element element, WebBeansModel model, + private void informInjectionPointDefError(InjectionPointDefinitionError exception , + Element element, WebBeansModel model, Result result ) { result.addError(element, model, exception.getMessage()); diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ProducerFieldAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ProducerFieldAnalyzer.java index 5e6944ddedee..2b4f477f28be 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ProducerFieldAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ProducerFieldAnalyzer.java @@ -34,13 +34,16 @@ import org.netbeans.modules.web.beans.analysis.analyzer.FieldElementAnalyzer.FieldAnalyzer; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; + /** * @author ads * */ -public class ProducerFieldAnalyzer extends AbstractProducerAnalyzer - implements FieldAnalyzer +public class ProducerFieldAnalyzer extends AbstractProducerAnalyzer + implements FieldAnalyzer { /* (non-Javadoc) @@ -52,8 +55,7 @@ public void analyze( VariableElement element, TypeMirror elementType, CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - if ( !AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, - compInfo )) + if (!AnnotationUtil.hasAnnotation(element, compInfo, PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { return; } @@ -75,7 +77,7 @@ protected void hasTypeVar( Element element, TypeMirror type, result.addError( element, NbBundle.getMessage( ProducerFieldAnalyzer.class, "ERR_ProducerHasTypeVar")); // NOI18N } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractProducerAnalyzer#hasWildCard(javax.lang.model.element.Element, javax.lang.model.type.TypeMirror, org.netbeans.api.java.source.CompilationInfo, java.util.List) */ @@ -96,7 +98,7 @@ private void checkSessionBean( VariableElement element, TypeElement parent, Set modifiers = element.getModifiers(); if ( !modifiers.contains(Modifier.STATIC)){ result.addError( element, NbBundle.getMessage( - ProducerFieldAnalyzer.class, + ProducerFieldAnalyzer.class, "ERR_NonStaticProducerSessionBean")); // NOI18N } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ScopedFieldAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ScopedFieldAnalyzer.java index e31692daa9b7..36efcec00fa4 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ScopedFieldAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/field/ScopedFieldAnalyzer.java @@ -33,6 +33,9 @@ import org.netbeans.modules.web.beans.api.model.WebBeansModel; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; + /** * @author ads @@ -47,8 +50,7 @@ public void analyze( VariableElement element, TypeMirror elementType, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { - if ( AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN_JAKARTA, model.getCompilationController())) + if (AnnotationUtil.hasAnnotation(element, model, PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { result.requireCdiEnabled(element, model); analyzeScope(element, model, cancel , result ); diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/AnnotationsAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/AnnotationsAnalyzer.java index e203a7eecd4f..fcc1523d9ce7 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/AnnotationsAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/AnnotationsAnalyzer.java @@ -38,13 +38,22 @@ import org.netbeans.modules.web.beans.hints.EditorAnnotationsHelper; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; + /** * @author ads * */ public class AnnotationsAnalyzer implements MethodAnalyzer { - + private static final String EJB = "ejb"; // NOI18N /* (non-Javadoc) @@ -54,7 +63,7 @@ public class AnnotationsAnalyzer implements MethodAnalyzer { public void analyze( ExecutableElement element, TypeMirror returnType, TypeElement parent, AtomicBoolean cancel , CdiAnalysisResult result ) { - checkProductionObserverDisposerInject( element , parent , + checkProductionObserverDisposerInject( element , parent , cancel , result ); if ( cancel.get()){ return; @@ -66,10 +75,8 @@ private void checkProductionObserverDisposerInject( CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - boolean isProducer = AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN_JAKARTA, compInfo); - boolean isInitializer = AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN_JAKARTA, compInfo); + boolean isProducer = AnnotationUtil.hasAnnotation(element, compInfo, PRODUCES_FQN_JAKARTA, PRODUCES_FQN); + boolean isInitializer = AnnotationUtil.hasAnnotation(element, compInfo, INJECT_FQN_JAKARTA, INJECT_FQN); int observesCount = 0; int disposesCount = 0; List parameters = element.getParameters(); @@ -77,13 +84,11 @@ private void checkProductionObserverDisposerInject( if ( cancel.get() ){ return; } - if ( AnnotationUtil.hasAnnotation( param, AnnotationUtil.OBSERVES_FQN, compInfo) - || AnnotationUtil.hasAnnotation( param, AnnotationUtil.OBSERVES_FQN_JAKARTA, compInfo)) + if (AnnotationUtil.hasAnnotation(param, compInfo, OBSERVES_FQN_JAKARTA, OBSERVES_FQN)) { observesCount++; } - if (AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN, compInfo) - || AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN_JAKARTA, compInfo)) + if (AnnotationUtil.hasAnnotation(param, compInfo, DISPOSES_FQN_JAKARTA, DISPOSES_FQN)) { disposesCount++; } @@ -128,7 +133,7 @@ else if ( observesCount >0 ){ AnnotationsAnalyzer.class, "ERR_BothAnnotationsMethod", // NOI18N firstAnnotation, secondAnnotation )); } - + // Test quantity of observer parameters if ( observesCount > 1){ result.addError( element, NbBundle.getMessage( @@ -139,21 +144,21 @@ else if ( disposesCount >1 ){ result.addError( element, NbBundle.getMessage( AnnotationsAnalyzer.class, "ERR_ManyDisposesParameter")); // NOI18N } - - // A producer/disposer method must be a non-abstract method . + + // A producer/disposer method must be a non-abstract method . checkAbstractMethod(element, result, isProducer, disposesCount>0); - - checkBusinessMethod( element , result, isProducer, + + checkBusinessMethod( element , result, isProducer, disposesCount >0 , observesCount > 0); - + if ( isInitializer ){ checkInitializerMethod(element, parent , result ); } } /** - * A producer/disposer/observer non-static method of a session bean class + * A producer/disposer/observer non-static method of a session bean class * should be a business method of the session bean. */ private void checkBusinessMethod( ExecutableElement element, @@ -197,11 +202,11 @@ else if ( isObserver ){ key = "ERR_ObserverNotBusiness"; // NOI18N } result.addError( element, NbBundle.getMessage( - AnnotationsAnalyzer.class, key)); + AnnotationsAnalyzer.class, key)); } } - private void checkInitializerMethod( ExecutableElement element, + private void checkInitializerMethod( ExecutableElement element, TypeElement parent, CdiAnalysisResult result ) { Set modifiers = element.getModifiers(); @@ -212,13 +217,13 @@ private void checkInitializerMethod( ExecutableElement element, "ERR_StaticInitMethod"; // NOI18N result.addError( element, NbBundle.getMessage( AnnotationsAnalyzer.class, key )); - } + } TypeMirror method = result.getInfo().getTypes().asMemberOf( (DeclaredType)parent.asType() , element); if ( method instanceof ExecutableType ){ - List typeVariables = + List typeVariables = ((ExecutableType)method).getTypeVariables(); - if ( typeVariables != null && typeVariables.size() > 0 ){ + if (typeVariables != null && !typeVariables.isEmpty()) { result.addError( element, NbBundle.getMessage( AnnotationsAnalyzer.class, "ERR_GenericInitMethod" ));// NOI18N } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/DelegateMethodAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/DelegateMethodAnalyzer.java index d7df2e80946e..4a4784315923 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/DelegateMethodAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/DelegateMethodAnalyzer.java @@ -38,6 +38,13 @@ import org.netbeans.modules.web.beans.hints.EditorAnnotationsHelper; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; + /** * @author ads @@ -58,8 +65,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, if (cancel.get()) { return; } - if (AnnotationUtil.hasAnnotation(param, AnnotationUtil.DELEGATE_FQN_JAKARTA, result.getInfo()) - || AnnotationUtil.hasAnnotation(param, AnnotationUtil.DELEGATE_FQN, result.getInfo())) + if (AnnotationUtil.hasAnnotation(param, result.getInfo(), DELEGATE_FQN_JAKARTA, DELEGATE_FQN)) { result.requireCdiEnabled(element); if (cancel.get()) { @@ -90,13 +96,12 @@ private void checkClassDefinition( TypeElement parent, ExecutableElement element, VariableElement param, CdiAnalysisResult result) { - if ( ! ( AnnotationUtil.hasAnnotation(parent, AnnotationUtil.DECORATOR, result.getInfo()) - || AnnotationUtil.hasAnnotation(parent, AnnotationUtil.DECORATOR_JAKARTA, result.getInfo()))) + if (!AnnotationUtil.hasAnnotation(parent, result.getInfo(), DECORATOR_JAKARTA, DECORATOR)) { - result.addError( param, - NbBundle.getMessage(DelegateFieldAnalizer.class, + result.addError( param, + NbBundle.getMessage(DelegateFieldAnalizer.class, "ERR_DelegateIsNotInDecorator")); // NOI18N - } + } } private void checkDelegateType( VariableElement element, int i, @@ -120,17 +125,16 @@ private void checkDelegateType( VariableElement element, int i, } } - private void checkMethodDefinition( ExecutableElement element, + private void checkMethodDefinition( ExecutableElement element, VariableElement param, CdiAnalysisResult result ) { if ( element.getKind() == ElementKind.CONSTRUCTOR ){ return; } - if (!(AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INJECT_FQN_JAKARTA, result.getInfo()))) + if (!AnnotationUtil.hasAnnotation(element, result.getInfo(), INJECT_FQN_JAKARTA, INJECT_FQN)) { - result.addError( param, - NbBundle.getMessage(DelegateMethodAnalyzer.class, + result.addError( param, + NbBundle.getMessage(DelegateMethodAnalyzer.class, "ERR_WrongDelegateMethod")); // NOI18N } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InjectionPointParameterAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InjectionPointParameterAnalyzer.java index 98432030816c..108eb297a785 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InjectionPointParameterAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InjectionPointParameterAnalyzer.java @@ -32,7 +32,6 @@ import javax.lang.model.type.TypeMirror; import org.netbeans.api.java.source.CompilationController; -import org.netbeans.api.java.source.ElementHandle; import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationHelper; import org.netbeans.modules.web.beans.analysis.CdiEditorAnalysisFactory; import org.netbeans.modules.web.beans.analysis.analyzer.AbstractDecoratorAnalyzer; @@ -49,13 +48,18 @@ import org.netbeans.spi.editor.hints.Severity; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED_JAKARTA; + /** * @author ads * */ -public class InjectionPointParameterAnalyzer - extends AbstractDecoratorAnalyzer implements MethodAnalyzer +public class InjectionPointParameterAnalyzer + extends AbstractDecoratorAnalyzer implements MethodAnalyzer { /* (non-Javadoc) @@ -63,7 +67,7 @@ public class InjectionPointParameterAnalyzer */ @Override public void analyze( ExecutableElement element, TypeMirror returnType, - TypeElement parent, WebBeansModel model , + TypeElement parent, WebBeansModel model , AtomicBoolean cancel , Result result ) { for (VariableElement var : element.getParameters()) { @@ -101,11 +105,9 @@ public void analyze( ExecutableElement element, TypeMirror returnType, if ( cancel.get()){ return; } - checkInjectionPointMetadata( var, element, parent , model , + checkInjectionPointMetadata( var, element, parent , model , cancel , result ); - if ( isDelegate - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DELEGATE_FQN_JAKARTA, model.getCompilationController())) + if ( isDelegate || AnnotationUtil.hasAnnotation(element, model, DELEGATE_FQN_JAKARTA, DELEGATE_FQN)) { return; } @@ -127,7 +129,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, } } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractDecoratorAnalyzer#addClassError(javax.lang.model.element.VariableElement, java.lang.Object, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, org.netbeans.api.java.source.CompilationInfo, java.util.List) */ @@ -136,12 +138,12 @@ protected void addClassError( VariableElement element, ExecutableElement method, TypeElement decoratedBean, WebBeansModel model, Result result ) { - result.addError( element , method, model, - NbBundle.getMessage(InjectionPointParameterAnalyzer.class, + result.addError( element , method, model, + NbBundle.getMessage(InjectionPointParameterAnalyzer.class, "ERR_FinalDecoratedBean", // NOI18N decoratedBean.getQualifiedName().toString())); } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractDecoratorAnalyzer#addMethodError(javax.lang.model.element.VariableElement, java.lang.Object, javax.lang.model.element.TypeElement, javax.lang.model.element.Element, org.netbeans.modules.web.beans.api.model.WebBeansModel, org.netbeans.modules.web.beans.analysis.analyzer.ModelAnalyzer.Result) */ @@ -157,9 +159,9 @@ protected void addMethodError( VariableElement element, decoratedBean.getQualifiedName().toString(), decoratedMethod.getSimpleName().toString())); } - + private TypeMirror getParameterType( VariableElement var, - ExecutableElement element, TypeElement parent , + ExecutableElement element, TypeElement parent , CompilationController controller ) { ExecutableType method = (ExecutableType)controller.getTypes().asMemberOf( @@ -169,7 +171,8 @@ private TypeMirror getParameterType( VariableElement var, int paramIndex = parameters.indexOf(var); return parameterTypes.get(paramIndex); } - + + @SuppressWarnings("UnnecessaryReturnStatement") private void checkInjectionPointMetadata( VariableElement var, ExecutableElement method, TypeElement parent, WebBeansModel model, AtomicBoolean cancel , Result result ) @@ -209,7 +212,7 @@ private void checkInjectionPointMetadata( VariableElement var, String scope = model.getScope(parent); if (scope != null && !AnnotationUtil.DEPENDENT.equals(scope) && !AnnotationUtil.DEPENDENT_JAKARTA.equals(scope)) { - result.addError(var, method, model, + result.addError(var, method, model, NbBundle.getMessage(InjectionPointParameterAnalyzer.class,"ERR_WrongQualifierInjectionPointMeta")); // NOI18N } } @@ -223,18 +226,14 @@ private void checkName( ExecutableElement element, VariableElement var, WebBeansModel model, Result result) { AnnotationMirror annotation = AnnotationUtil.getAnnotationMirror( - var, AnnotationUtil.NAMED_JAKARTA, model.getCompilationController()); - if (annotation == null) { - annotation = AnnotationUtil.getAnnotationMirror( - var, AnnotationUtil.NAMED, model.getCompilationController()); - } + var, model.getCompilationController(), NAMED_JAKARTA, NAMED); if (annotation != null) { - result.addNotification( Severity.WARNING , var, element , model, - NbBundle.getMessage(InjectionPointAnalyzer.class, + result.addNotification( Severity.WARNING , var, element , model, + NbBundle.getMessage(InjectionPointAnalyzer.class, "WARN_NamedInjectionPoint")); // NOI18N - if ( annotation.getElementValues().size() == 0 ){ - result.addError(var, element, model, - NbBundle.getMessage( InjectionPointParameterAnalyzer.class, + if ( annotation.getElementValues().isEmpty() ){ + result.addError(var, element, model, + NbBundle.getMessage( InjectionPointParameterAnalyzer.class, "ERR_ParameterNamedInjectionPoint")); // NOI18N } } @@ -251,13 +250,13 @@ private void checkResult( DependencyInjectionResult res , severity = Severity.ERROR; } String message = ((DependencyInjectionResult.Error)res).getMessage(); - result.addNotification(severity, element , method , + result.addNotification(severity, element , method , model, message); } } - private void informInjectionPointDefError(InjectionPointDefinitionError exception , - Element element, WebBeansModel model, + private void informInjectionPointDefError(InjectionPointDefinitionError exception , + Element element, WebBeansModel model, Result result ) { result.addError(element, model, exception.getMessage()); diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InterceptedMethodAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InterceptedMethodAnalyzer.java index 3ae47369d9db..aa7e18c7ec3f 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InterceptedMethodAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/InterceptedMethodAnalyzer.java @@ -47,12 +47,15 @@ import org.netbeans.spi.editor.hints.Severity; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_JAKARTA; + /** * @author ads * */ -public class InterceptedMethodAnalyzer extends AbstractInterceptedElementAnalyzer +public class InterceptedMethodAnalyzer extends AbstractInterceptedElementAnalyzer implements MethodAnalyzer { @@ -75,7 +78,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, } if (AnnotationUtil.isLifecycleCallback(element, model.getCompilationController() )) { if (hasInterceptorBindings) { - result.addNotification( Severity.WARNING, element, model, + result.addNotification( Severity.WARNING, element, model, NbBundle.getMessage(InterceptedMethodAnalyzer.class, "WARN_CallbackInterceptorBinding")); // NOI18N } @@ -87,7 +90,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, List interceptors = interceptorResult .getResolvedInterceptors(); AnnotationHelper helper = null; - if ( interceptors.size() >0 ){ + if (!interceptors.isEmpty()) { helper = new AnnotationHelper(model.getCompilationController()); } for (TypeElement interceptor : interceptors) { @@ -118,9 +121,9 @@ public void analyze( ExecutableElement element, TypeMirror returnType, if (cancel.get()) { return; } - + Set modifiers = element.getModifiers(); - if ( modifiers.contains( Modifier.STATIC ) || + if ( modifiers.contains( Modifier.STATIC ) || modifiers.contains( Modifier.PRIVATE)) { return; @@ -135,23 +138,21 @@ public void analyze( ExecutableElement element, TypeMirror returnType, } if ( hasInterceptorBindings){ if ( finalMethod ){ - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage( InterceptedMethodAnalyzer.class, "ERR_FinalInterceptedMethod")); // NOI18N } - if (finalClass - && !AnnotationUtil.hasAnnotation(parent, AnnotationUtil.INTERCEPTOR, model.getCompilationController()) - && !AnnotationUtil.hasAnnotation(parent, AnnotationUtil.INTERCEPTOR_JAKARTA, model.getCompilationController())) + if (finalClass && !AnnotationUtil.hasAnnotation(parent, model, INTERCEPTOR_JAKARTA, INTERCEPTOR)) { - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage( InterceptedMethodAnalyzer.class, "ERR_FinalInterceptedClass")); // NOI18N } } } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractInterceptedElementAnalyzer#getInterceptorBindings(javax.lang.model.element.Element, org.netbeans.modules.web.beans.api.model.WebBeansModel) */ diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ProducerMethodAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ProducerMethodAnalyzer.java index 58a7e9651861..051dcbc9d36e 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ProducerMethodAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ProducerMethodAnalyzer.java @@ -34,13 +34,18 @@ import org.netbeans.modules.web.beans.analysis.analyzer.MethodElementAnalyzer.MethodAnalyzer; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES_JAKARTA; + /** * @author ads * */ -public class ProducerMethodAnalyzer extends AbstractProducerAnalyzer - implements MethodAnalyzer +public class ProducerMethodAnalyzer extends AbstractProducerAnalyzer + implements MethodAnalyzer { /* (non-Javadoc) @@ -50,8 +55,7 @@ public class ProducerMethodAnalyzer extends AbstractProducerAnalyzer public void analyze( ExecutableElement element, TypeMirror returnType, TypeElement parent, AtomicBoolean cancel , CdiAnalysisResult result ) { - if (!(AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN_JAKARTA, result.getInfo()))) + if (!AnnotationUtil.hasAnnotation(element, result.getInfo(), PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { return; } @@ -65,7 +69,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, } checkSpecializes( element , result ); } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractProducerAnalyzer#hasTypeVar(javax.lang.model.element.Element, javax.lang.model.type.TypeMirror, org.netbeans.modules.web.beans.analysis.analyzer.ElementAnalyzer.Result) */ @@ -76,7 +80,7 @@ protected void hasTypeVar( Element element, TypeMirror type, result.addError( element, NbBundle.getMessage( ProducerMethodAnalyzer.class, "ERR_ProducerReturnIsTypeVar")); // NOI18N } - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.AbstractProducerAnalyzer#hasWildCard(javax.lang.model.element.Element, javax.lang.model.type.TypeMirror, org.netbeans.modules.web.beans.analysis.analyzer.ElementAnalyzer.Result) */ @@ -87,18 +91,17 @@ protected void hasWildCard( Element element, TypeMirror type, result.addError(element, NbBundle.getMessage( ProducerMethodAnalyzer.class,"ERR_ProducerReturnHasWildcard")); // NOI18N } - + private void checkSpecializes(ExecutableElement element, CdiAnalysisResult result ) { - if (!(AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES_JAKARTA, result.getInfo()))) + if (!(AnnotationUtil.hasAnnotation(element, result.getInfo(), SPECIALIZES_JAKARTA, SPECIALIZES))) { return; } Set modifiers = element.getModifiers(); if ( modifiers.contains( Modifier.STATIC )){ result.addError( element, NbBundle.getMessage( - ProducerMethodAnalyzer.class, + ProducerMethodAnalyzer.class, "ERR_StaticSpecializesProducer")); // NOI18N } CompilationInfo compInfo = result.getInfo(); @@ -113,11 +116,10 @@ private void checkSpecializes(ExecutableElement element, CdiAnalysisResult resul enclosingTypeElement( element ); TypeMirror typeDirectSuper = containingClass.getSuperclass(); if (!superClass.equals(compInfo.getTypes().asElement(typeDirectSuper)) - || (!AnnotationUtil.hasAnnotation(overridenMethod, AnnotationUtil.PRODUCES_FQN, compInfo) - && !AnnotationUtil.hasAnnotation(overridenMethod, AnnotationUtil.PRODUCES_FQN_JAKARTA, compInfo))) + || (!AnnotationUtil.hasAnnotation(overridenMethod, compInfo, PRODUCES_FQN_JAKARTA, PRODUCES_FQN))) { result.addError( element, NbBundle.getMessage( - ProducerMethodAnalyzer.class, + ProducerMethodAnalyzer.class, "ERR_NoDirectSpecializedProducer")); // NOI18N } } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ScopedMethodAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ScopedMethodAnalyzer.java index 7462659245f0..03c5cc52e3ab 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ScopedMethodAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/ScopedMethodAnalyzer.java @@ -34,6 +34,9 @@ import org.netbeans.modules.web.beans.api.model.WebBeansModel; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; + /** * @author ads @@ -42,7 +45,7 @@ public class ScopedMethodAnalyzer extends AbstractScopedAnalyzer implements MethodAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.MethodModelAnalyzer.MethodAnalyzer#analyze(javax.lang.model.element.ExecutableElement, javax.lang.model.type.TypeMirror, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.concurrent.atomic.AtomicBoolean, org.netbeans.modules.web.beans.analysis.analyzer.ModelAnalyzer.Result) */ @@ -51,8 +54,7 @@ public void analyze( ExecutableElement element, TypeMirror returnType, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN_JAKARTA, model.getCompilationController())) + if (AnnotationUtil.hasAnnotation(element, model, PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { result.requireCdiEnabled(element,model); analyzeScope(element, model, cancel, result ); @@ -77,8 +79,8 @@ protected void checkScope( TypeElement scopeElement, Element element, return; } if ( hasTypeVarParameter( returnType )){ - result.addError( element, model, - NbBundle.getMessage(ScopedMethodAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(ScopedMethodAnalyzer.class, "ERR_WrongScopeParameterizedProducerReturn", // NOI18N scopeElement.getQualifiedName().toString())); } @@ -111,11 +113,11 @@ private void checkPassivationCapable( TypeElement scopeElement, return; } if ( returnTypeElement.getModifiers().contains( Modifier.FINAL )){ - result.addError( element, model, - NbBundle.getMessage(ScopedMethodAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(ScopedMethodAnalyzer.class, "ERR_NotPassivationProducerReturn", // NOI18N scopeElement.getQualifiedName().toString())); } } - + } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/TypedMethodAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/TypedMethodAnalyzer.java index 4950039c943a..274643a1972f 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/TypedMethodAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/method/TypedMethodAnalyzer.java @@ -38,6 +38,9 @@ import org.netbeans.modules.web.beans.analysis.analyzer.MethodElementAnalyzer.MethodAnalyzer; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; + /** * @author ads @@ -85,8 +88,7 @@ protected void checkSpecializes( Element element, TypeMirror elementType, List restrictedTypes, AtomicBoolean cancel , CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - if (!AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN, compInfo) - && !AnnotationUtil.hasAnnotation(element, AnnotationUtil.PRODUCES_FQN_JAKARTA, compInfo)) + if (!AnnotationUtil.hasAnnotation(element, compInfo, PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { return; } @@ -107,25 +109,25 @@ protected void checkSpecializes( Element element, TypeMirror elementType, if ( cancel.get()){ return; } - List restrictedSuper = getRestrictedTypes(overriddenMethod, + List restrictedSuper = getRestrictedTypes(overriddenMethod, compInfo, cancel); if ( cancel.get()){ return; } if ( restrictedSuper == null ) { - if (!hasUnrestrictedOverridenType(elementType, + if (!hasUnrestrictedOverridenType(elementType, restrictedTypes, compInfo,overriddenMethod, superClass) ) { result.addError( element, NbBundle.getMessage( - TypedMethodAnalyzer.class, "ERR_BadSpecializesMethod")); // NOI18N + TypedMethodAnalyzer.class, "ERR_BadSpecializesMethod")); // NOI18N } } - else { + else { if (!hasRestrictedType(elementType, restrictedTypes, compInfo, restrictedSuper)) { result.addError( element, NbBundle.getMessage( - TypedMethodAnalyzer.class, "ERR_BadSpecializesMethod")); // NOI18N + TypedMethodAnalyzer.class, "ERR_BadSpecializesMethod")); // NOI18N } } } @@ -150,11 +152,11 @@ private boolean hasRestrictedType( TypeMirror elementType, return true; } else { - Set specializedBeanTypes = getElements( + Set specializedBeanTypes = getElements( restrictedSuper, compInfo); - Set restrictedElements = getElements(restrictedTypes, + Set restrictedElements = getElements(restrictedTypes, compInfo); - restrictedElements.add( compInfo.getElements().getTypeElement( + restrictedElements.add( compInfo.getElements().getTypeElement( Object.class.getCanonicalName())); return restrictedElements.containsAll( specializedBeanTypes ); } @@ -183,7 +185,7 @@ else if ( returnOverriden.getKind().isPrimitive() ) { else if ( returnOverriden instanceof DeclaredType ){ Element returnElement = compInfo.getTypes().asElement( returnOverriden); if ( returnElement instanceof TypeElement ){ - return hasUnrestrictedType((TypeElement)returnElement, + return hasUnrestrictedType((TypeElement)returnElement, restrictedTypes, compInfo); } } @@ -195,9 +197,9 @@ private boolean hasUnrestrictedType( TypeElement overriden, { Set specializedBeanTypes = getUnrestrictedBeanTypes( overriden, compInfo); - Set restrictedElements = getElements(restrictedTypes, + Set restrictedElements = getElements(restrictedTypes, compInfo); - restrictedElements.add( compInfo.getElements().getTypeElement( + restrictedElements.add( compInfo.getElements().getTypeElement( Object.class.getCanonicalName())); return restrictedElements.containsAll(specializedBeanTypes); } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/AnnotationsAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/AnnotationsAnalyzer.java index d39453a7b8dd..c76acb5ca040 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/AnnotationsAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/AnnotationsAnalyzer.java @@ -35,13 +35,34 @@ import org.openide.util.NbBundle; import org.netbeans.spi.editor.hints.Severity; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.ALTERNATVE; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.ALTERNATVE_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DELEGATE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DISPOSES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.OBSERVES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.PRODUCES_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES_JAKARTA; + /** * @author ads * */ public class AnnotationsAnalyzer implements ClassAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.ClassElementAnalyzer.ClassAnalyzer#analyze(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement, org.netbeans.api.java.source.CompilationInfo, java.util.List, java.util.concurrent.atomic.AtomicBoolean) */ @@ -52,14 +73,12 @@ public void analyze( TypeElement element, TypeElement parent, checkDecoratorInterceptor( element , cancel, result ); } - private void checkDecoratorInterceptor( TypeElement element, + private void checkDecoratorInterceptor( TypeElement element, AtomicBoolean cancel , CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - boolean isDecorator = AnnotationUtil.hasAnnotation(element, AnnotationUtil.DECORATOR, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DECORATOR_JAKARTA, compInfo); - boolean isInterceptor = AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR, compInfo) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_JAKARTA, compInfo); + boolean isDecorator = AnnotationUtil.hasAnnotation(element, compInfo, DECORATOR_JAKARTA, DECORATOR); + boolean isInterceptor = AnnotationUtil.hasAnnotation(element, compInfo, INTERCEPTOR_JAKARTA, INTERCEPTOR); if ( isDecorator && isInterceptor ){ result.addError( element, NbBundle.getMessage( AnnotationsAnalyzer.class, "ERR_DecoratorInterceptor"));// NOI18N @@ -101,11 +120,10 @@ private void checkDecoratorInterceptor( TypeElement element, private void checkSpecializes( TypeElement element, CdiAnalysisResult result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES_JAKARTA, result.getInfo())) + if (AnnotationUtil.hasAnnotation(element, result.getInfo(), SPECIALIZES_JAKARTA, SPECIALIZES)) { result.addNotification(Severity.WARNING, element, NbBundle.getMessage( - AnnotationsAnalyzer.class, + AnnotationsAnalyzer.class, "WARN_SpecializesInterceptorDecorator")); // NOI18N } } @@ -113,18 +131,16 @@ private void checkSpecializes( TypeElement element, CdiAnalysisResult result ) private void checkAlternatives( TypeElement element, CdiAnalysisResult result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.ALTERNATVE, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.ALTERNATVE_JAKARTA, result.getInfo())) + if (AnnotationUtil.hasAnnotation(element, result.getInfo(), ALTERNATVE_JAKARTA, ALTERNATVE)) { result.addNotification(Severity.WARNING, element, NbBundle.getMessage( - AnnotationsAnalyzer.class, + AnnotationsAnalyzer.class, "WARN_AlternativeInterceptorDecorator")); // NOI18N - } + } } private void checkNamed( TypeElement element, CdiAnalysisResult result ) { - if ( AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED, result.getInfo()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED_JAKARTA, result.getInfo())) + if ( AnnotationUtil.hasAnnotation(element, result.getInfo(), NAMED_JAKARTA, NAMED)) { result.addNotification(Severity.WARNING, element, NbBundle.getMessage( AnnotationsAnalyzer.class, "WARN_NamedInterceptorDecorator")); // NOI18N @@ -142,17 +158,12 @@ private void checkDelegateInjectionPoint( TypeElement element, { count +=delegateInjectionPointCount(child, compInfo); } - else if ( ! ( - AnnotationUtil.hasAnnotation(child, AnnotationUtil.INJECT_FQN, compInfo ) - || AnnotationUtil.hasAnnotation(child, AnnotationUtil.INJECT_FQN_JAKARTA, compInfo ) - )) + else if (!AnnotationUtil.hasAnnotation(child, compInfo, INJECT_FQN_JAKARTA, INJECT_FQN)) { continue; } if ((child.getKind() == ElementKind.FIELD - && AnnotationUtil.hasAnnotation(child, AnnotationUtil.DELEGATE_FQN, compInfo)) - || (child.getKind() == ElementKind.FIELD - && AnnotationUtil.hasAnnotation(child, AnnotationUtil.DELEGATE_FQN_JAKARTA, compInfo))) { + && AnnotationUtil.hasAnnotation(child, compInfo, DELEGATE_FQN_JAKARTA, DELEGATE_FQN))) { count++; } else if ( child.getKind() ==ElementKind.METHOD ) @@ -165,18 +176,15 @@ else if ( child.getKind() ==ElementKind.METHOD ) AnnotationsAnalyzer.class, "ERR_IncorrectDelegateCount")); // NOI18N } } - - private int delegateInjectionPointCount(Element element , + + private int delegateInjectionPointCount(Element element , CompilationInfo compInfo) { int result=0; ExecutableElement method = (ExecutableElement)element; List parameters = method.getParameters(); for (VariableElement par : parameters) { - if ( - AnnotationUtil.hasAnnotation(par, AnnotationUtil.DELEGATE_FQN, compInfo) - || AnnotationUtil.hasAnnotation(par, AnnotationUtil.DELEGATE_FQN_JAKARTA, compInfo) - ) + if (AnnotationUtil.hasAnnotation(par, compInfo, DELEGATE_FQN_JAKARTA, DELEGATE_FQN)) { result++; } @@ -198,22 +206,19 @@ private void checkMethods( TypeElement element, boolean isDecorator, CdiAnalysisResult result ) { CompilationInfo compInfo = result.getInfo(); - List methods = ElementFilter.methodsIn( + List methods = ElementFilter.methodsIn( element.getEnclosedElements()); for (ExecutableElement method : methods) { - boolean isProducer = AnnotationUtil.hasAnnotation(method, AnnotationUtil.PRODUCES_FQN, compInfo) - || AnnotationUtil.hasAnnotation(method, AnnotationUtil.PRODUCES_FQN_JAKARTA, compInfo); + boolean isProducer = AnnotationUtil.hasAnnotation(method, compInfo, PRODUCES_FQN_JAKARTA, PRODUCES_FQN); boolean isDisposer = false; boolean isObserver = false; List parameters = method.getParameters(); for (VariableElement param : parameters) { - if (AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN, compInfo) - || AnnotationUtil.hasAnnotation(param, AnnotationUtil.DISPOSES_FQN_JAKARTA, compInfo)) { + if (AnnotationUtil.hasAnnotation(param, compInfo, DISPOSES_FQN_JAKARTA, DISPOSES_FQN)) { isDisposer = true; break; } - if ( AnnotationUtil.hasAnnotation( param , AnnotationUtil.OBSERVES_FQN, compInfo) - || AnnotationUtil.hasAnnotation( param , AnnotationUtil.OBSERVES_FQN_JAKARTA, compInfo)) + if ( AnnotationUtil.hasAnnotation( param , compInfo, OBSERVES_FQN_JAKARTA, OBSERVES_FQN)) { isObserver = true; break; @@ -221,14 +226,14 @@ private void checkMethods( TypeElement element, boolean isDecorator, } if ( isProducer || isDisposer || isObserver ){ result.addError( element, NbBundle.getMessage( - AnnotationsAnalyzer.class, getMethodErrorKey(isDecorator, - isProducer, isDisposer) , + AnnotationsAnalyzer.class, getMethodErrorKey(isDecorator, + isProducer, isDisposer) , method.getSimpleName().toString())); break; } } } - + private String getMethodErrorKey(boolean isDecorator, boolean isProducer, boolean isDisposer ) { @@ -261,11 +266,10 @@ else if ( isDisposer ){ private void checkProducerFields( TypeElement element, boolean isDecorator, CdiAnalysisResult result ) { - List fields = ElementFilter.fieldsIn( + List fields = ElementFilter.fieldsIn( element.getEnclosedElements() ); for (VariableElement field : fields) { - if ( AnnotationUtil.hasAnnotation(field, AnnotationUtil.PRODUCES_FQN_JAKARTA, result.getInfo()) - || AnnotationUtil.hasAnnotation(field, AnnotationUtil.PRODUCES_FQN, result.getInfo())) + if (AnnotationUtil.hasAnnotation(field, result.getInfo(), PRODUCES_FQN_JAKARTA, PRODUCES_FQN)) { String key= isDecorator ? "ERR_DecoratorHasProducerField": "ERR_IntrerceptorHasProducerField"; // NOI18N diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/CtorsAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/CtorsAnalyzer.java index 9b0921b152c8..efcaef46f04d 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/CtorsAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/CtorsAnalyzer.java @@ -30,6 +30,9 @@ import org.netbeans.modules.web.beans.analysis.analyzer.ClassElementAnalyzer.ClassAnalyzer; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; + /** * @author ads @@ -51,10 +54,7 @@ public void analyze( TypeElement element, TypeElement parent, if ( cancel.get() ){ return; } - if ( - AnnotationUtil.hasAnnotation( ctor , AnnotationUtil.INJECT_FQN, result.getInfo()) - || AnnotationUtil.hasAnnotation( ctor , AnnotationUtil.INJECT_FQN_JAKARTA, result.getInfo()) - ) + if (AnnotationUtil.hasAnnotation(ctor, result.getInfo(), INJECT_FQN_JAKARTA, INJECT_FQN)) { result.requireCdiEnabled( ctor ); injectCtorCount++; diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/InterceptedBeanAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/InterceptedBeanAnalyzer.java index b0bd3744c729..a2a882cc40ca 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/InterceptedBeanAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/InterceptedBeanAnalyzer.java @@ -36,15 +36,18 @@ import org.netbeans.modules.web.beans.hints.EditorAnnotationsHelper; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INTERCEPTOR_JAKARTA; + /** * @author ads * */ -public class InterceptedBeanAnalyzer extends AbstractInterceptedElementAnalyzer - implements ClassAnalyzer +public class InterceptedBeanAnalyzer extends AbstractInterceptedElementAnalyzer + implements ClassAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.ClassModelAnalyzer.ClassAnalyzer#analyze(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @@ -53,11 +56,10 @@ public void analyze( TypeElement element, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.INTERCEPTOR_JAKARTA, model.getCompilationController())) + if (AnnotationUtil.hasAnnotation(element, model, INTERCEPTOR_JAKARTA, INTERCEPTOR)) { result.requireCdiEnabled(element, model); - // rule should not be applied to interceptor + // rule should not be applied to interceptor return ; } boolean hasIBindings = hasInterceptorBindings(element, model); @@ -66,12 +68,12 @@ public void analyze( TypeElement element, TypeElement parent, EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance(result); ElementHandle handle = ElementHandle.create(element); if ( helper != null ){ - helper.addInterceptedBean( result , + helper.addInterceptedBean( result , handle.resolve( result.getInfo())); } } - - + + Set modifiers = element.getModifiers(); boolean isFinal = modifiers.contains(Modifier.FINAL); List methods = ElementFilter.methodsIn( @@ -85,7 +87,7 @@ public void analyze( TypeElement element, TypeElement parent, if ( !modifiers.contains( Modifier.FINAL )){ continue; } - if ( modifiers.contains( Modifier.STATIC ) || + if ( modifiers.contains( Modifier.STATIC ) || modifiers.contains( Modifier.PRIVATE)) { continue; @@ -100,13 +102,13 @@ public void analyze( TypeElement element, TypeElement parent, return; } if (hasIBindings && isFinal) { - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage( InterceptedBeanAnalyzer.class, "ERR_FinalInterceptedBean")); // NOI18N } if (hasIBindings && badMethod != null) { - result.addError(element, model, + result.addError(element, model, NbBundle.getMessage( InterceptedBeanAnalyzer.class, "ERR_InterceptedBeanHasFinalMethod", badMethod diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ManagedBeansAnalizer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ManagedBeansAnalizer.java index 74c44472d126..de1b291e41f8 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ManagedBeansAnalizer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ManagedBeansAnalizer.java @@ -39,16 +39,21 @@ import org.netbeans.spi.editor.hints.Severity; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.DECORATOR_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.INJECT_FQN_JAKARTA; + /** * @author ads * */ public class ManagedBeansAnalizer implements ClassAnalyzer { - + private static final String EXTENSION = "javax.enterprise.inject.spi.Extension"; //NOI18N private static final String EXTENSION_JAKARTA = "jakarta.enterprise.inject.spi.Extension"; //NOI18N - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.ClassModelAnalyzer.ClassAnalyzer#analyze(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @@ -57,7 +62,7 @@ public void analyze( TypeElement element, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { - boolean cdiManaged = model.getQualifiers( element, true ).size()>0; + boolean cdiManaged = !model.getQualifiers(element, true).isEmpty(); if ( !cdiManaged ){ return; } @@ -88,7 +93,7 @@ private void checkDecorators( TypeElement element, WebBeansModel model, Result result ) { Collection decorators = model.getDecorators(element); - if ( decorators!= null && decorators.size() >0 ){ + if (decorators != null && !decorators.isEmpty()) { EditorAnnotationsHelper helper = EditorAnnotationsHelper.getInstance(result); ElementHandle handle = ElementHandle.create(element); if ( helper != null ){ @@ -108,10 +113,10 @@ private void checkImplementsExtension( TypeElement element, return; } TypeMirror elementType = element.asType(); - if ( model.getCompilationController().getTypes().isSubtype( + if ( model.getCompilationController().getTypes().isSubtype( elementType, extension.asType())){ - result.addNotification(Severity.WARNING, element, - model, NbBundle.getMessage( ManagedBeansAnalizer.class, + result.addNotification(Severity.WARNING, element, + model, NbBundle.getMessage( ManagedBeansAnalizer.class, "WARN_QualifiedElementExtension")); // NOI18N } } @@ -121,16 +126,15 @@ private void checkAbstract( TypeElement element, { Set modifiers = element.getModifiers(); if (modifiers.contains(Modifier.ABSTRACT)) { - if (AnnotationUtil.hasAnnotation(element, AnnotationUtil.DECORATOR, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.DECORATOR_JAKARTA, model.getCompilationController())) { + if (AnnotationUtil.hasAnnotation(element, model, DECORATOR_JAKARTA, DECORATOR)) { return; } // element is abstract and has no Decorator annotation result.addNotification( Severity.WARNING, element, model, - NbBundle.getMessage(ManagedBeansAnalizer.class, + NbBundle.getMessage(ManagedBeansAnalizer.class, "WARN_QualifierAbstractClass")); // NOI18N - } + } } private void checkInner( TypeElement element, TypeElement parent, @@ -141,8 +145,8 @@ private void checkInner( TypeElement element, TypeElement parent, } Set modifiers = element.getModifiers(); if ( !modifiers.contains( Modifier.STATIC )){ - result.addError(element, model, - NbBundle.getMessage(ManagedBeansAnalizer.class, + result.addError(element, model, + NbBundle.getMessage(ManagedBeansAnalizer.class, "ERR_NonStaticInnerType")); // NOI18N } } @@ -150,7 +154,7 @@ private void checkInner( TypeElement element, TypeElement parent, private void checkCtor( TypeElement element, WebBeansModel model, Result result ) { - List ctors = ElementFilter.constructorsIn( + List ctors = ElementFilter.constructorsIn( element.getEnclosedElements()); for (ExecutableElement ctor : ctors) { Set modifiers = ctor.getModifiers(); @@ -158,20 +162,17 @@ private void checkCtor( TypeElement element, WebBeansModel model, continue; } List parameters = ctor.getParameters(); - if ( parameters.size() ==0 ){ + if (parameters.isEmpty()) { return; } - if ( - AnnotationUtil.hasAnnotation(ctor, AnnotationUtil.INJECT_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(ctor, AnnotationUtil.INJECT_FQN_JAKARTA, model.getCompilationController()) - ) + if (AnnotationUtil.hasAnnotation(ctor, model, INJECT_FQN_JAKARTA, INJECT_FQN)) { return; } } // there is no non-private ctors without params or annotated with @Inject - result.addNotification( Severity.WARNING, element, model, - NbBundle.getMessage(ManagedBeansAnalizer.class, + result.addNotification( Severity.WARNING, element, model, + NbBundle.getMessage(ManagedBeansAnalizer.class, "WARN_QualifierNoCtorClass")); // NOI18N } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/NamedModelAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/NamedModelAnalyzer.java index 9d264494e9c3..6b266b32bcd6 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/NamedModelAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/NamedModelAnalyzer.java @@ -30,6 +30,11 @@ import org.netbeans.modules.web.beans.api.model.WebBeansModel; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NAMED_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SPECIALIZES_JAKARTA; + /** * @author ads @@ -45,16 +50,12 @@ public void analyze( TypeElement element, TypeElement parent, WebBeansModel model, AtomicBoolean cancel, Result result ) { - if ( ! ( AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES, model.getCompilationController())) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SPECIALIZES_JAKARTA, model.getCompilationController())) + if (!AnnotationUtil.hasAnnotation(element, model, SPECIALIZES_JAKARTA, SPECIALIZES)) { return; } result.requireCdiEnabled(element, model); - if ( !( - AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.NAMED_JAKARTA, model.getCompilationController()) - )) + if (!AnnotationUtil.hasAnnotation(element, model, NAMED_JAKARTA, NAMED)) { return; } diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ScopedBeanAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ScopedBeanAnalyzer.java index d94dc998344a..a8bfa5c5c401 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ScopedBeanAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/ScopedBeanAnalyzer.java @@ -18,22 +18,17 @@ */ package org.netbeans.modules.web.beans.analysis.analyzer.type; -import java.io.Serializable; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; @@ -45,15 +40,19 @@ import org.netbeans.spi.editor.hints.Severity; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NORMAL_SCOPE_FQN; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.NORMAL_SCOPE_FQN_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STATEFUL; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STATEFUL_JAKARTA; /** * @author ads * */ -public class ScopedBeanAnalyzer extends AbstractScopedAnalyzer - implements ClassAnalyzer +public class ScopedBeanAnalyzer extends AbstractScopedAnalyzer + implements ClassAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.ClassModelAnalyzer.ClassAnalyzer#analyze(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @@ -101,26 +100,23 @@ private void checkPassivationCapable( TypeElement scopeElement, return; } if ( AnnotationUtil.isSessionBean(element, model.getCompilationController())){ - if ( - AnnotationUtil.hasAnnotation(element, AnnotationUtil.STATEFUL, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.STATEFUL_JAKARTA, model.getCompilationController()) - ) + if (AnnotationUtil.hasAnnotation(element, model, STATEFUL_JAKARTA, STATEFUL)) { return; } else { - result.addError(element, model , + result.addError(element, model , NbBundle.getMessage(ScopedBeanAnalyzer.class, "ERR_NotPassivationSessionBean", // NOI18N - scopeElement.getQualifiedName().toString())); + scopeElement.getQualifiedName().toString())); return; } } if ( !isSerializable(element, model) ){ - result.addError(element, model , + result.addError(element, model , NbBundle.getMessage(ScopedBeanAnalyzer.class, "ERR_NotPassivationManagedBean", // NOI18N - scopeElement.getQualifiedName().toString())); + scopeElement.getQualifiedName().toString())); } // TODO : all interceptors ans decorators of bean should be also passivation capable } @@ -141,7 +137,7 @@ private void checkInterceptorDecorator( TypeElement scopeElement, AnnotationUtil.INTERCEPTOR, AnnotationUtil.DECORATOR); } if ( annotationMirror!= null ){ - result.addNotification( Severity.WARNING, element, model, + result.addNotification( Severity.WARNING, element, model, NbBundle.getMessage(ScopedBeanAnalyzer.class, "WARN_ScopedDecoratorInterceptor" )); // NOI18N } @@ -154,13 +150,13 @@ private void checkParameterizedBean( TypeElement scopeElement, if ( scopeElement.getQualifiedName().contentEquals(AnnotationUtil.DEPENDENT) || scopeElement.getQualifiedName().contentEquals(AnnotationUtil.DEPENDENT_JAKARTA)){ return; - } + } result.requireCdiEnabled(element, model); TypeMirror type = element.asType(); if ( type instanceof DeclaredType ){ List typeArguments = ((DeclaredType)type).getTypeArguments(); - if ( typeArguments.size() != 0 ){ - result.addError(element, model, + if (!typeArguments.isEmpty()) { + result.addError(element, model, NbBundle.getMessage(ScopedBeanAnalyzer.class, "ERR_IncorrectScopeForParameterizedBean" )); // NOI18N } @@ -175,15 +171,15 @@ private void checkPublicField( TypeElement scopeElement, Element element, return; } result.requireCdiEnabled(element, model); - List fields = ElementFilter.fieldsIn( + List fields = ElementFilter.fieldsIn( element.getEnclosedElements()); for (VariableElement field : fields) { Set modifiers = field.getModifiers(); if ( modifiers.contains(Modifier.PUBLIC ) && (!modifiers.contains(Modifier.STATIC) || !model.isCdi11OrLater())){ - result.addError(element, model , + result.addError(element, model , NbBundle.getMessage(ScopedBeanAnalyzer.class, - "ERR_IcorrectScopeWithPublicField", + "ERR_IcorrectScopeWithPublicField", field.getSimpleName().toString())); return; } @@ -193,8 +189,7 @@ private void checkPublicField( TypeElement scopeElement, Element element, private void checkProxiability( TypeElement scopeElement, Element element, WebBeansModel model, Result result ) { - boolean isNormal = AnnotationUtil.hasAnnotation(scopeElement, AnnotationUtil.NORMAL_SCOPE_FQN, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(scopeElement, AnnotationUtil.NORMAL_SCOPE_FQN_JAKARTA, model.getCompilationController()); + boolean isNormal = AnnotationUtil.hasAnnotation(scopeElement, model, NORMAL_SCOPE_FQN_JAKARTA, NORMAL_SCOPE_FQN); if ( isNormal ){ result.requireCdiEnabled(element, model); checkFinal( element , model, result ); @@ -209,8 +204,8 @@ private void checkFinal( Element element, WebBeansModel model, } Set modifiers = element.getModifiers(); if ( modifiers.contains( Modifier.FINAL) ){ - result.addError( element, model, - NbBundle.getMessage(ScopedBeanAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(ScopedBeanAnalyzer.class, "ERR_FinalScopedClass")); return; } @@ -219,7 +214,7 @@ private void checkFinal( Element element, WebBeansModel model, for (ExecutableElement method : methods) { modifiers = method.getModifiers(); if (modifiers.contains(Modifier.FINAL)) { - result.addNotification( Severity.WARNING, method, model, + result.addNotification( Severity.WARNING, method, model, NbBundle.getMessage( ScopedBeanAnalyzer.class, "WARN_FinalScopedClassMethod")); diff --git a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/SessionBeanAnalyzer.java b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/SessionBeanAnalyzer.java index 2cee32dc972e..343ffb3972a5 100644 --- a/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/SessionBeanAnalyzer.java +++ b/enterprise/web.beans/src/org/netbeans/modules/web/beans/analysis/analyzer/type/SessionBeanAnalyzer.java @@ -30,13 +30,18 @@ import org.netbeans.modules.web.beans.api.model.WebBeansModel; import org.openide.util.NbBundle; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SINGLETON; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.SINGLETON_JAKARTA; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STATELESS; +import static org.netbeans.modules.web.beans.analysis.analyzer.AnnotationUtil.STATELESS_JAKARTA; + /** * @author ads * */ public class SessionBeanAnalyzer implements ClassAnalyzer { - + /* (non-Javadoc) * @see org.netbeans.modules.web.beans.analysis.analyzer.ClassModelAnalyzer.ClassAnalyzer#analyze(javax.lang.model.element.TypeElement, javax.lang.model.element.TypeElement, org.netbeans.modules.web.beans.api.model.WebBeansModel, java.util.List, org.netbeans.api.java.source.CompilationInfo, java.util.concurrent.atomic.AtomicBoolean) */ @@ -45,17 +50,15 @@ public void analyze( TypeElement element, TypeElement parent, WebBeansModel model, AtomicBoolean cancel , Result result ) { - boolean isSingleton = AnnotationUtil.hasAnnotation(element, AnnotationUtil.SINGLETON, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.SINGLETON_JAKARTA, model.getCompilationController()); - boolean isStateless = AnnotationUtil.hasAnnotation(element, AnnotationUtil.STATELESS, model.getCompilationController()) - || AnnotationUtil.hasAnnotation(element, AnnotationUtil.STATELESS_JAKARTA, model.getCompilationController()); + boolean isSingleton = AnnotationUtil.hasAnnotation(element, model, SINGLETON_JAKARTA, SINGLETON); + boolean isStateless = AnnotationUtil.hasAnnotation(element, model, STATELESS_JAKARTA, STATELESS); if ( cancel.get() ){ return; } try { String scope = model.getScope( element ); if ( isSingleton ) { - if ( AnnotationUtil.APPLICATION_SCOPED.equals( scope ) + if ( AnnotationUtil.APPLICATION_SCOPED.equals( scope ) || AnnotationUtil.DEPENDENT.equals( scope ) || AnnotationUtil.APPLICATION_SCOPED_JAKARTA.equals( scope ) || AnnotationUtil.DEPENDENT_JAKARTA.equals( scope ) ) @@ -63,16 +66,16 @@ public void analyze( TypeElement element, TypeElement parent, return; } result.requireCdiEnabled(element, model); - result.addError( element, model, - NbBundle.getMessage(SessionBeanAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(SessionBeanAnalyzer.class, "ERR_InvalidSingletonBeanScope")); // NOI18N } else if ( isStateless ) { if (!AnnotationUtil.DEPENDENT.equals(scope) && !AnnotationUtil.DEPENDENT_JAKARTA.equals(scope)) { - result.addError( element, model, - NbBundle.getMessage(SessionBeanAnalyzer.class, + result.addError( element, model, + NbBundle.getMessage(SessionBeanAnalyzer.class, "ERR_InvalidStatelessBeanScope")); // NOI18N } } @@ -82,8 +85,8 @@ else if ( isStateless ) { informCdiException(e, element, model, result ); } } - - private void informCdiException(CdiException exception , Element element, + + private void informCdiException(CdiException exception , Element element, WebBeansModel model, Result result ) { result.addError(element, model, exception.getMessage());