List of usage examples for org.eclipse.jdt.core IType getTypeParameterSignatures
String[] getTypeParameterSignatures() throws JavaModelException;
From source file:org.jboss.tools.cdi.internal.core.validation.CDICoreValidator.java
License:Open Source License
private void validateSessionBean(ISessionBean bean) { IAnnotationDeclaration declaration = CDIUtil.getDifferentScopeDeclarationThanDepentend(bean); if (declaration != null) { IType type = bean.getBeanClass(); try {/*from www . j a v a 2 s . c o m*/ /* * 3.2. Session beans * - session bean with a parameterized bean class declares any scope other than @Dependent */ String[] typeVariables = type.getTypeParameterSignatures(); if (typeVariables.length > 0) { addProblem(CDIValidationMessages.ILLEGAL_SCOPE_FOR_SESSION_BEAN_WITH_GENERIC_TYPE, CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN, declaration, bean.getResource()); } else { if (bean.isStateless()) { /* * 3.2. Session beans * - session bean specifies an illegal scope (a stateless session bean must belong to the @Dependent pseudo-scope) */ if (declaration != null) { addProblem(CDIValidationMessages.ILLEGAL_SCOPE_FOR_STATELESS_SESSION_BEAN, CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN, declaration, bean.getResource()); } } else if (bean.isSingleton()) { /* * 3.2. Session beans * - session bean specifies an illegal scope (a singleton bean must belong to either the @ApplicationScoped scope or to the @Dependent pseudo-scope) */ if (declaration != null) { declaration = CDIUtil.getDifferentScopeDeclarationThanApplicationScoped(bean); } if (declaration != null) { addProblem(CDIValidationMessages.ILLEGAL_SCOPE_FOR_SINGLETON_SESSION_BEAN, CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN, declaration, bean.getResource()); } } } } catch (JavaModelException e) { CDICorePlugin.getDefault().logError(e); } } /* * 3.2.4. Specializing a session bean * - session bean class annotated @Specializes does not directly extend the bean class of another session bean */ IAnnotationDeclaration specializesDeclaration = bean.getSpecializesAnnotationDeclaration(); if (specializesDeclaration != null) { saveAllSuperTypesAsLinkedResources(bean); IBean sBean = bean.getSpecializedBean(); if (sBean == null) { // The specializing bean extends nothing addProblem(CDIValidationMessages.ILLEGAL_SPECIALIZING_SESSION_BEAN, CDIPreferences.ILLEGAL_SPECIALIZING_BEAN, specializesDeclaration, bean.getResource()); } else if (!CDIUtil.isSessionBean(sBean)) { // The specializing bean directly extends a non-session bean class addProblem(CDIValidationMessages.ILLEGAL_SPECIALIZING_SESSION_BEAN, CDIPreferences.ILLEGAL_SPECIALIZING_BEAN, specializesDeclaration, bean.getResource()); } } }
From source file:org.jboss.tools.cdi.internal.core.validation.CDICoreValidator.java
License:Open Source License
private void validateManagedBean(IClassBean bean) { /*//w w w . j av a 2s . c om * 3.1. Managed beans * - the bean class of a managed bean is annotated with both the @Interceptor and @Decorator stereotypes */ IAnnotationDeclaration decorator = bean.getAnnotation(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME); IAnnotationDeclaration interceptor = bean.getAnnotation(CDIConstants.INTERCEPTOR_ANNOTATION_TYPE_NAME); if (decorator != null && interceptor != null) { addProblem(CDIValidationMessages.BOTH_INTERCEPTOR_AND_DECORATOR, CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR, decorator, bean.getResource()); addProblem(CDIValidationMessages.BOTH_INTERCEPTOR_AND_DECORATOR, CDIPreferences.BOTH_INTERCEPTOR_AND_DECORATOR, interceptor, bean.getResource()); } IAnnotationDeclaration declaration = CDIUtil.getDifferentScopeDeclarationThanDepentend(bean); if (declaration != null) { IType type = bean.getBeanClass(); try { /* * 3.1. Managed beans * - managed bean with a public field declares any scope other than @Dependent */ IField[] fields = type.getFields(); for (IField field : fields) { if (Flags.isPublic(field.getFlags()) && !Flags.isStatic(field.getFlags())) { ITextSourceReference fieldReference = CDIUtil.convertToSourceReference(field.getNameRange(), bean.getResource(), field); addProblem(CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD, CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN, fieldReference, bean.getResource(), ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_PUBLIC_FIELD_ID); } } /* * 3.1. Managed beans * - managed bean with a parameterized bean class declares any scope other than @Dependent */ String[] typeVariables = type.getTypeParameterSignatures(); if (typeVariables.length > 0) { addProblem(CDIValidationMessages.ILLEGAL_SCOPE_FOR_MANAGED_BEAN_WITH_GENERIC_TYPE, CDIPreferences.ILLEGAL_SCOPE_FOR_BEAN, declaration, bean.getResource()); } } catch (JavaModelException e) { CDICorePlugin.getDefault().logError(e); } } /* * 3.1.4. Specializing a managed bean * - managed bean class annotated @Specializes does not directly extend the bean class of another managed bean */ IAnnotationDeclaration specializesDeclaration = bean.getSpecializesAnnotationDeclaration(); if (specializesDeclaration != null) { saveAllSuperTypesAsLinkedResources(bean); try { IBean sBean = bean.getSpecializedBean(); if (sBean != null) { if (sBean instanceof ISessionBean || sBean.getAnnotation(CDIConstants.STATELESS_ANNOTATION_TYPE_NAME) != null || sBean.getAnnotation(CDIConstants.SINGLETON_ANNOTATION_TYPE_NAME) != null) { // The specializing bean directly extends an enterprise bean class addProblem(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, CDIPreferences.ILLEGAL_SPECIALIZING_BEAN, specializesDeclaration, bean.getResource()); } else { // Validate the specializing bean extends a non simple bean boolean hasDefaultConstructor = true; IMethod[] methods = sBean.getBeanClass().getMethods(); for (IMethod method : methods) { if (method.isConstructor()) { if (Flags.isPublic(method.getFlags()) && method.getParameterNames().length == 0) { hasDefaultConstructor = true; break; } hasDefaultConstructor = false; } } if (!hasDefaultConstructor) { addProblem(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, CDIPreferences.ILLEGAL_SPECIALIZING_BEAN, specializesDeclaration, bean.getResource()); } } } else { // The specializing bean extends nothing addProblem(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, CDIPreferences.ILLEGAL_SPECIALIZING_BEAN, specializesDeclaration, bean.getResource()); } } catch (JavaModelException e) { CDICorePlugin.getDefault().logError(e); } } try { /* * 9.3. Binding an interceptor to a bean * - managed bean has a class level interceptor binding and is declared final or has a non-static, non-private, final method * - non-static, non-private, final method of a managed bean has a method level interceptor binding */ Collection<IInterceptorBinding> bindings = bean.getInterceptorBindings(); if (!bindings.isEmpty()) { if (Flags.isFinal(bean.getBeanClass().getFlags())) { ITextSourceReference reference = CDIUtil.convertToSourceReference( bean.getBeanClass().getNameRange(), bean.getResource(), bean.getBeanClass()); addProblem(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_CLASS, CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource()); } else { IMethod[] methods = bean.getBeanClass().getMethods(); for (int i = 0; i < methods.length; i++) { int flags = methods[i].getFlags(); if (Flags.isFinal(flags) && !Flags.isStatic(flags) && !Flags.isPrivate(flags)) { ITextSourceReference reference = CDIUtil.convertToSourceReference( methods[i].getNameRange(), bean.getResource(), methods[i]); addProblem(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_METHOD, CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource()); } } } } else { for (IBeanMethod method : bean.getAllMethods()) { if (!method.getInterceptorBindings().isEmpty()) { if (Flags.isFinal(bean.getBeanClass().getFlags())) { ITextSourceReference reference = CDIUtil.convertToSourceReference( bean.getBeanClass().getNameRange(), bean.getResource(), bean.getBeanClass()); addProblem(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_CLASS, CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource()); } else { IMethod sourceMethod = method.getMethod(); int flags = sourceMethod.getFlags(); if (Flags.isFinal(flags) && !Flags.isStatic(flags) && !Flags.isPrivate(flags)) { ITextSourceReference reference = CDIUtil.convertToSourceReference( sourceMethod.getNameRange(), bean.getResource(), sourceMethod); addProblem(CDIValidationMessages.ILLEGAL_INTERCEPTOR_BINDING_METHOD, CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD, reference, bean.getResource()); } } } } } /* * 6.6.4 Validation of passivation capable beans and dependencies * - If a managed bean which declares a passivating scope is not passivation capable, then the container automatically detects the problem and treats it as a deployment problem. */ if (bean.getScopeDeclarations().size() < 2) { // Ignore broken beans with multiple scope declarations. IScope scope = bean.getScope(); if (scope != null && scope.isNorlmalScope()) { IAnnotationDeclaration normalScopeDeclaration = scope .getAnnotationDeclaration(CDIConstants.NORMAL_SCOPE_ANNOTATION_TYPE_NAME); if (normalScopeDeclaration != null) { boolean passivatingScope = "true" .equalsIgnoreCase("" + normalScopeDeclaration.getMemberValue("passivating")); if (passivatingScope) { boolean passivatingCapable = false; for (IParametedType type : bean.getAllTypes()) { if ("java.io.Serializable".equals(type.getType().getFullyQualifiedName())) { passivatingCapable = true; break; } } if (!passivatingCapable) { ITextSourceReference reference = CDIUtil.convertToSourceReference( bean.getBeanClass().getNameRange(), bean.getResource(), bean.getBeanClass()); addProblem( MessageFormat.format(CDIValidationMessages.NOT_PASSIVATION_CAPABLE_BEAN, bean.getElementName(), scope.getSourceType().getElementName()), CDIPreferences.NOT_PASSIVATION_CAPABLE_BEAN, reference, bean.getResource(), NOT_PASSIVATION_CAPABLE_BEAN_ID); } } } } } } catch (JavaModelException e) { CDICorePlugin.getDefault().logError(e); } }
From source file:org.jboss.tools.common.java.ParametedTypeFactory.java
License:Open Source License
public ParametedType newParametedType(IType type) { ParametedType parametedType = new ParametedType(); if (type != null && !type.isBinary()) { ISourceRange r = null;/*from w w w. j ava2 s .co m*/ try { r = type.getNameRange(); } catch (CoreException e) { CommonCorePlugin.getDefault().logError(e); } if (r != null) { parametedType = new TypeDeclaration(parametedType, type.getResource(), r.getOffset(), r.getLength()); } } parametedType.setFactory(this); parametedType.setType(type); if (type != null) parametedType.setSignature(Signature.C_RESOLVED + type.getFullyQualifiedName() + Signature.C_SEMICOLON); String[] ps = null; try { ps = type.getTypeParameterSignatures(); } catch (JavaModelException e) { CommonCorePlugin.getDefault().logError(e); } if (ps != null && ps.length > 0) { for (int i = 0; i < ps.length; i++) { try { ParametedType p = getParametedTypeForParameter(type, ps[i], null); if (p != null) parametedType.addParameter(p); } catch (JavaModelException e) { CommonCorePlugin.getDefault().logError(e); } } } return parametedType; }
From source file:org.jboss.tools.common.java.ParametedTypeFactory.java
License:Open Source License
public ParametedType getParametedType(IMember context, IParametedType basetype, String typeSignature) throws JavaModelException { if (typeSignature == null) return null; if (basetype != null) { ParametedType param = ((ParametedType) basetype).findParameter(typeSignature); if (param != null) return param; }/* w w w. j av a2 s .c o m*/ IType contextType = context instanceof IType ? (IType) context : context.getDeclaringType(); String key = context == null || context.isBinary() || OBJECT.equals(typeSignature) ? typeSignature : contextType.getFullyQualifiedName() + "+" + typeSignature; if (cache.containsKey(key)) return cache.get(key); ParametedType result = new ParametedType(); result.setFactory(this); result.setSignature(typeSignature); typeSignature = typeSignature.substring(result.getArrayIndex()); char c = typeSignature.length() == 0 ? '\0' : typeSignature.charAt(0); if (primitives.containsKey(c) && typeSignature.length() == 1) { typeSignature = primitives.get(c); result.setSignature(result.getArrayPrefix() + typeSignature); result.setPrimitive(true); } else if (c == Signature.C_EXTENDS) { typeSignature = typeSignature.substring(1); result.setUpper(true); } else if (c == Signature.C_SUPER) { typeSignature = typeSignature.substring(1); result.setLower(true); } else if (c == Signature.C_STAR && typeSignature.length() == 1) { result.setUpper(true); return result; } int startToken = typeSignature.indexOf(Signature.C_GENERIC_START); if (startToken < 0) { String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeSignature); if (resovedTypeName == null) return null; if (!context.isBinary() || typeSignature.charAt(0) == Signature.C_TYPE_VARIABLE) { StringBuffer ns = new StringBuffer(); ns.append(result.getArrayPrefix()); if (result.isLower()) ns.append(Signature.C_SUPER); if (result.isUpper()) ns.append(Signature.C_EXTENDS); ns.append(Signature.C_RESOLVED).append(resovedTypeName).append(Signature.C_SEMICOLON); result.setSignature(ns.toString()); } IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName); if (type != null) { result.setType(type); cache.put(key, result); return result; } if (context instanceof IMethod) { String[] ps = ((IMethod) context).getTypeParameterSignatures(); for (int i = 0; i < ps.length; i++) { ParametedType st = getParametedTypeForParameter(context, ps[i], result); if (st != null) { if (st.getSignature().indexOf(Signature.C_COLON) >= 0) { CommonCorePlugin.getDefault().logWarning("Wrong signature=" + st.getSignature()); } return st; } } } String[] ps = contextType.getTypeParameterSignatures(); for (int i = 0; i < ps.length; i++) { ParametedType st = getParametedTypeForParameter(contextType, ps[i], result); if (st != null) return st; } } else { int endToken = typeSignature.lastIndexOf(Signature.C_GENERIC_END); if (endToken < startToken) return null; String typeName = typeSignature.substring(0, startToken) + typeSignature.substring(endToken + 1); String resovedTypeName = EclipseJavaUtil.resolveTypeAsString(contextType, typeName); if (resovedTypeName == null) return null; IType type = EclipseJavaUtil.findType(context.getJavaProject(), resovedTypeName); if (type != null) { result.setType(type); cache.put(key, result); StringBuffer newParams = new StringBuffer(); String[] paramSignatures = null; try { paramSignatures = Signature.getTypeArguments(typeSignature); } catch (IllegalArgumentException e) { CommonCorePlugin.getDefault().logError(e); } if (paramSignatures != null) for (String paramSignature : paramSignatures) { ParametedType param = getParametedType(context, basetype, paramSignature); if (param == null) { param = new ParametedType(); param.setSignature(paramSignature); } result.addParameter(param); newParams.append(param.getSignature()); } if (!context.isBinary()) { StringBuffer ns = new StringBuffer(); ns.append(result.getArrayPrefix()); if (result.isLower()) ns.append(Signature.C_SUPER); if (result.isUpper()) ns.append(Signature.C_EXTENDS); ns.append(Signature.C_RESOLVED).append(resovedTypeName).append(Signature.C_GENERIC_START) .append(newParams).append(Signature.C_GENERIC_END).append(Signature.C_SEMICOLON); result.setSignature(ns.toString()); } return result; } } return null; }
From source file:org.seasar.kijimuna.core.internal.rtti.DefaultRtti.java
License:Apache License
private HashMap createGenericMap(IType type) { HashMap map = new HashMap(); try {// w w w . java 2s .c o m String[] signatures = type.getTypeParameterSignatures(); for (int i = 0; i < signatures.length; i++) { String signature = signatures[i]; int separator = signature.indexOf(':'); String generic = signature.substring(0, separator); String extend = signature.substring(separator + 1); if (extend.length() > 0) { extend = Signature.toString(extend); } else { extend = "java.lang.Object"; } map.put(generic, extend); } } catch (JavaModelException e) { } return map; }